<?php $db = new Mypdo(); ?><?php


if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){

$persManager = new PersonneManager($db);
$locManager = new LocationManager($db);
$pers = $persManager->getList();

?>
<h1>Liste des personnes</h1>
<table class="tableau" >
    <tr>
        <th>Nom</th>
        <th>Prenom</th>
        <th>Location</th>
        <th>Détail</th>
    </tr>
    <?php foreach ($pers as $valeur) {
        $loc = $locManager->getLocationByIdPers($valeur->getIdPers());


//  var_dump($loc);
        ?>

        <tr>
            <td><?php
                    echo $valeur->getNomPers();


                ?></td>
            <td><?php
                    echo $valeur->getPrenomPers();

                ?></td>
            <td><?php
                if(gettype($loc) == 'object'){
                    echo $loc->getNomLoc();
                }else{
                    foreach($loc as $val){
                        echo $val->getNomLoc().'<br/>';
                    }
                }

                ?></td>
            <td><input id="detail" name="detail" type="button" onclick="document.location.href='index.php?page=117&id=<?php echo $valeur->getIdPers(); ?>'" /></td>
        </tr>

    <?php
    } ?>
</table>

<?php }else{
    header('Location: index.php');
}